package com.neo.web;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class GetLocation {
    public static String GetLocationMsg(double latitude, double longitude) {
        String message = "";
        String url = String.format(
                "http://maps.google.cn/maps/api/geocode/json?latlng=%s,%s&language=CN",
                latitude, longitude);
        URL myURL = null;
        URLConnection httpsConn = null;
        try {
            myURL = new URL(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            httpsConn = (URLConnection) myURL.openConnection();
            if (httpsConn != null) {
                InputStreamReader insr = new InputStreamReader(
                        httpsConn.getInputStream(), "UTF-8");
                BufferedReader br = new BufferedReader(insr);
                String data = null;
                while ((data = br.readLine()) != null) {
                    message = message + data;
                }
                insr.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return message;
    }

    public final static void main(String[] args) {
        System.out.println(GetLocationMsg(30.5763307666, 104.0712219292));
    }
}